package ru.xeden.web.html.dom;

import java.io.PrintWriter;

import ru.xeden.web.html.RenderContext;
import ru.xeden.web.html.component.IComponent;

/**
 * A type of node that contains text.
 */
public final class Text 
    extends Node
    implements IComponent
{
    private final String text;

    public Text(String text)
    {
        this.text = text;
    }

    boolean isEmpty()
    {
        return text == null || text.length() == 0 || text.trim().length() == 0;
    }

    @Override
    public void toMarkup(RenderContext markupContext, PrintWriter writer)
    {
        String encoded = markupContext.getMarkupModel().encode(text);
        writer.print(encoded);
    }
}
